﻿Public Class clsHWSetting
    Public Function selectAllLHJ() As DataTable
        Try
            Dim szSql As String = String.Empty
            'szSql = String.Empty
            'szSql &= "SELECT * FROM sf.t_sys_param WHERE param_key = ? "
            'Dim dtSysParam As DataTable = DBacs.ExecuteSql(szSql, -1, "LH_Out_Warning_Minute")
            szSql = String.Empty
            szSql &= "SELECT a.*,b.prod_spec_name FROM sf.t_hw_setting a "
            szSql &= "left join sf.t_prod_spec b on a.prod_spec_id = b.prod_spec_id "
            szSql &= " WHERE a.factory_id =? AND a.workshop_id = ? AND a.equip_type_id = ? "
            szSql &= " and a.status=? AND a.deleted = false "
            'szSql &= " or a.last_minutes<=? "
            szSql &= " ORDER BY a.equip_id ASC"
            'Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", "LH", "LHJ", "3", dtSysParam.Rows(0)("param_value").ToString())

            Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", "LH", "LHJ", "3")
            If IsNothing(dt) Then
                selectAllLHJ = New DataTable
            Else
                selectAllLHJ = dt
            End If
        Catch ex As Exception
            Throw New Exception("exception:" & ex.Message.ToString, ex)
        End Try
    End Function

    Public Function selectAllLHJ1() As DataTable
        Try
            Dim szSql As String = String.Empty
            szSql = String.Empty
            szSql &= "SELECT * FROM sf.t_hw_setting WHERE factory_id =? AND workshop_id = ? "
            szSql &= " AND equip_type_id = ? AND deleted = false ORDER BY equip_id ASC"
            Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", "LH", "LHJ")
            If IsNothing(dt) Then
                selectAllLHJ1 = New DataTable
            Else
                selectAllLHJ1 = dt
            End If
        Catch ex As Exception
            Throw New Exception("exception:" & ex.Message.ToString, ex)
        End Try
    End Function

    Public Function selectLHJbyID(equip_id As String) As DataTable
        Dim szSql As String = String.Empty
        szSql &= "SELECT * FROM sf.t_hw_setting WHERE factory_id =? AND workshop_id = ? and equip_type_id = ? and equip_id = ?"
        szSql &= " and status=? and last_minutes>=? and last_minutes<=? and prod_id is not null and prod_spec_id is not null AND deleted = false ORDER BY equip_id ASC"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", "LH", "LHJ", equip_id, "3", "0", "10")

        If IsNothing(dt) Then
            selectLHJbyID = New DataTable
        Else
            selectLHJbyID = dt
        End If
    End Function

    Public Function selectByTy(ws As String, type As String, type_name As String, status As String) As DataTable
        Dim szSql As String = String.Empty
        szSql &= "SELECT * "
        szSql &= "  FROM sf.t_hw_setting "
        szSql &= "  WHERE factory_id =? "
        szSql &= "  AND workshop_id = ? "
        szSql &= "  AND equip_type_id = ?"
        szSql &= "  AND type_name = ?"
        szSql &= "  AND status <> ?"
        szSql &= "  AND deleted = false"
        szSql &= "  ORDER BY workshop_id,equip_id "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", ws, type, type_name, status)
        If IsNothing(dt) Then
            selectByTy = New DataTable
        Else
            selectByTy = dt
        End If
    End Function

    Public Function SetLHJstatus(status As String, lhj As String) As Integer
        Dim szSql As String = "update sf.t_hw_setting set status = ? where workshop_id = ? and equip_type_id = ? and equip_id = ?"
        Return DBacs.ExecuteUpdateSql(szSql, -1, status, "LH", "LHJ", lhj)
    End Function

End Class
